layui.use(['form','layer','upload','layedit'],function(){
	   var form = layui.form
       layer = parent.layer === undefined ? layui.layer : top.layer,
       $ = layui.jquery,
       laydate = layui.laydate,
       laytpl = layui.laytpl,
       upload = layui.upload;
	   var layedit = layui.layedit;
  
	  var editIndex = layedit.build('suggCont', {
	      height: 400,
	      uploadImage: {
	            url: "https://www.idjglobalapp.com/app-servce/v1/api/upload"
	      }
	  });

	    //普通图片上传
	    var uploadInst = upload.render({
	    	elem: '#test1'
	            ,url: 'https://www.idjglobalapp.com/app-servce/v1/api/upload' //改成您自己的上传接口
	            ,method: 'POST'
	            ,done: function(res){
	                //上传完毕
	                if(res.code == 1){
	                	layer.msg('上传成功') 
	                	$('#demo1').attr('src', res.data);
	                }
	             }
	    });
	    
	    $("#LAY_layedit_1").contents().find("body[contenteditable]").prop("contenteditable",false);
	    
	    form.on('select(status)', function(data){
	    	if(data.value == '1'){
	    		$("#diva").show();
	    		$("#divb").hide();
	    	}else if(data.value == '2'){
	    		$("#divb").show();
	    		$("#diva").hide();
	    	}else{
	    		$("#diva").show();
	    		$("#divb").hide();
	    	}
	    });
	    
	    // 表单提交事件
	    form.on('submit(btnSubmit)', function (data) {
	    	var contents = layedit.getContent(editIndex);
	    	var bannerType = $("#status").find("option:selected").val();
	    	var pic =$("#demo1").attr("src");
	    	var bannerId =$("#bannerId").val();
	    	var bannerLink = $("#bannerLink").val();
	    	var data = {
	    			bannerId: bannerId,
	    			contents: contents,
	    			bannerType: bannerType,
	    			bannerPic: pic,
	    			bannerLink:bannerLink,
	    			bannerStatus:1
	    	}
	    	// 异步请求
	    	$.ajax({
	    		url: Feng.ctxPath + "/modular/banner/update",
	    		data: JSON.stringify(data),
	    		type: "post",
	    		contentType: "application/json;charset=UTF-8",
	    		async: false,//关闭异步请求
	    		dataType: "json",
	    		success: function (data) {
	    			if (data.code == 200) {
	    				Feng.success("操作成功！");
	    				//传给上个页面，刷新table用
	    				 window.parent.location.reload();
	    				 var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	    			     parent.layer.close(index);
	    			} else {
	    				Feng.success("操作失败！" + data.message);
	    			}
	    		}
	    	,
	    	error: function (data) {
	    		Feng.error("添加失败！" + data.message)
	    	}
	    	});
	    });
	    
});